package wht.jly.forum.utils.validatecode.image;

import java.awt.image.BufferedImage;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 图形验证码
 *
 * @author lanyangji
 * @date 2019/3/2 17:10
 */
public class ImageValidateCode implements Serializable {

    private static final long serialVersionUID = -5144116856649235653L;

    /**
     * 验证码
     */
    private String code;

    /**
     * 过期时间
     */
    private LocalDateTime expireTime;

    /**
     * 图形验证码图片
     */
    private BufferedImage image;

    /**
     * 构造器
     *
     * @param code          验证码
     * @param expireIn      过期时间间隔
     * @param image         验证码图片
     */
    public ImageValidateCode(String code, Long expireIn, BufferedImage image) {
        this.code = code;
        // 过期时间是在当前时间上，加上设置的过期时间间隔
        this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
        this.image = image;
    }

    /**
     * 是否过期
     *
     * @return
     */
    public boolean isExpired() {
        return LocalDateTime.now().isAfter(expireTime);
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
    }

    public BufferedImage getImage() {
        return image;
    }

    public void setImage(BufferedImage image) {
        this.image = image;
    }

    public ImageValidateCode() {
    }
}
